package sslh.Utility;

import java.util.*;
import sslh.*;

/** 
 CommonClass ��ժҪ˵����
*/
public class Hours extends ArrayList
{
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region construction
	public static final String FullHours = "0,1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,18,19,20,21,22,23";
	public Hours()
	{
	}
	public Hours(String hours)
	{
		this.setText(hours);
	}
	public Hours(boolean IsFullHours)
	{
		if (IsFullHours)
		{
			this.setText(FullHours);
		}
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion construction
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region attribution

	private boolean HasChanged = false;
	private String _Text = "";

	public final String getText()
	{
		if (HasChanged)
		{
			_Text = "";
			for (int i = 0;i < this.size();i++)
			{
				_Text += "," + super.get(i).toString();
			}
			_Text = _Text.substring(1);
			HasChanged = false;
		}
		return _Text;
	}
	public final void setText(String value)
	{
		_Text = value;
		this.clear();
		if (_Text.length() > 0)
		{
			String[] shours = _Text.split("[,]", -1);
			for (String s : shours)
			{
				this.add(Integer.parseInt(s));
			}
			this.TrimToSize();
		}
		HasChanged = false;
	}
	public final int getItem(int index)
	{
		if (index >= this.size())
		{
			int a = 1;
			a = a;
		}
		return (int)super.get(index);
	}
	public final void setItem(int index, int value)
	{
		super.set(index, value);
		HasChanged = true;
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion attribution
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#region method
	@Override
	public int Add(Object value)
	{
		HasChanged = true;
		return super.add(value);
	}
	@Override
	public void Remove(Object obj)
	{
		HasChanged = true;
		super.remove(obj);
	}
	@Override
	public void RemoveAt(int index)
	{
		HasChanged = true;
		super.remove(index);
	}

	@Override
	public String toString()
	{
		String output = "";
		if (this.size() > 0)
		{
			int current = this.get(0);
			int iBegin = current;
			int iEnd;
			for (int i = 0;i < this.size();i++)
			{
				if (this.get(i) != current)
				{
					iEnd = current;
					output += String.valueOf(iBegin) + ":00~" + String.valueOf(iEnd) + ":00 ";
					current = iBegin = this.get(i);
				}
				current++;
			}
			iEnd = current;
			output += String.valueOf(iBegin) + ":00~" + String.valueOf(iEnd) + ":00";
		}
		return output;
	}
	/** 
	 ���������,ȡ������
	 
	 @param hour1
	 @param hour2
	 @return 
	*/
	public static Hours OpMultiply(Hours hour1, Hours hour2)
	{
		Hours hour = new Hours();
		int h1,h2,i1 = 0,i2 = 0;
		while (i1 < hour1.size() && i2 < hour2.size())
		{
			h1 = hour1.get(i1);
			h2 = hour2.get(i2);
			if (h1 == h2)
			{
				i1++;
				i2++;
				hour.add(h1);
			}
			else if (h1 < h2)
			{
				i1++;
			}
			else
			{
				i2++;
			}
		}
		hour.TrimToSize();
		return hour;
	}
	/** 
	 ���������,ȡ������
	 
	 @param hour1
	 @param hour2
	 @return 
	*/
	public static Hours OpAddition(Hours hour1, Hours hour2)
	{
		Hours hour = new Hours();
		int h1,h2,i1 = 0,i2 = 0;
		while (i1 < hour1.size() && i2 < hour2.size())
		{
			h1 = hour1.get(i1);
			h2 = hour2.get(i2);
			if (h1 == h2)
			{
				i1++;
				i2++;
				hour.add(h1);
			}
			else if (h1 < h2)
			{
				i1++;
				hour.add(h1);
			}
			else
			{
				i2++;
				hour.add(h2);
			}
		}
		for (;i1 < hour1.size();i1++)
		{
			h1 = hour1.get(i1);
			hour.add(h1);
		}
		for (;i2 < hour2.size();i2++)
		{
			h2 = hour2.get(i2);
			hour.add(h2);
		}
		hour.TrimToSize();
		return hour;
	}
	/** 
	 ���������,ȡ��
	 
	 @param hour1
	 @return 
	*/
	public static Hours OpUnaryNegation(Hours hour1)
	{
		Hours hour = new Hours();
		int i,j = 0;
		for (i = 0;i < 24 && j < hour1.size();i++)
		{
			if (i < hour1.get(j))
			{
				hour.add(i);
			}
			else
			{
				j++;
			}
		}
		for (;i < 24;i++)
		{
			hour.add(i);
		}
		hour.TrimToSize();
		return hour;
	}
//C# TO JAVA CONVERTER TODO TASK: There is no preprocessor in Java:
		///#endregion method
}